package com.itlong.cloud.utils.network.http;

import javax.servlet.http.HttpServletRequest;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

/**
 * <desc>
 *      IO工具类。
 * <desc/>
 *
 * @craeteDate 2017/9/21
 */
public class IOHandle {


    /**
    * <desc>
    *     读取IO流里的参数.
    * <desc/>
    *
    * @param {@link javax.servlet.http.HttpServletRequest} request 。
    * @return 字符数据
    * @author Wenchao.L
    * @createDate  2017/9/21
    */
    public static String getNetWorkIOData(HttpServletRequest request) throws IOException {
        InputStream inputStream = null;
        BufferedReader in = null;
        StringBuffer sb = new StringBuffer();
        try {
            inputStream = request.getInputStream();
            String s;
            in = new BufferedReader(new InputStreamReader(inputStream, "UTF-8"));
            while ((s = in.readLine()) != null) {
                sb.append(s);
            }
        } catch (IOException e) {
            throw new IOException();
        }finally {
            in.close();
            inputStream.close();
        }
        return sb.toString();
    }

}
